Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various UndefinedBehaviorSanitizer warnings #315

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ccawley2011
Copy link

This fixes all warnings encountered when running the tests, except for two errors in toys/lsb/seq.c that I'm not sure how to fix properly.

The first commit is taken from libxmp/libxmp@a2f88d0.

@landley
Copy link
Owner

landley commented Jan 17, 2022

The first patch identifies itself as a false positive.

In the second, free(NULL) is a NOP so fine (says posix) so whatever the test decides in that case is ok, and what's the problem with postincrementing a null pointer we never use again? Not applying either, they don't fix anything real, just mollify a static analyzer I don't use.

@landley
Copy link
Owner

landley commented Jan 17, 2022

If qsort() is fed an array length of zero, and either reads from or writes to the first element of the array, it's making an access past the end of the array. That would be a bug in qsort.

@landley
Copy link
Owner

landley commented Jan 17, 2022

As an amateur computer historian (https://landley.net/history/mirror etc) I'm curious: what's the last processor that DIDN'T use two's complement for integer math? (Has there been one with a posix build environment?)

@@ -141,7 +145,7 @@ static void do_blkid(int fd, char *name)

len = fstypes[i].label_len;
if (!FLAG(U) && len) {
s = toybuf+fstypes[i].label_off-off;
s = toybuf+(fstypes[i].label_off-off);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this changes the result of the computation, I'm pretty sure that would be a compiler bug?

if (fstypes[i].magic_len+fstypes[i].magic_offset-off > sizeof(toybuf)) {
pass++;
continue;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which entry in fs_types[] has magic/len straddle a 4k boundary? We're supplying the input data here, it's a known set of table entries, the test above this is "we haven't advanced into this block yet", and quite intentionally none of the regions it needs to probe are across a 4k boundary.

Maybe I'm missing something, but... how can this trigger?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants